#region Summary

// 
// Owner : JackieHan 
// 
// Solution : DailyCollection 
// 
// Project : Jackie.Utility.Condition.Test
// 
// File : TestAllDefine.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : 测试所有定义的词法分析
// 
// History : 
//			2011-05-25 17:45:58	    Create 
// 

#endregion

#region Using

using System;
using System.Text.RegularExpressions;
using Jackie.Utility.Condition.Domain.Interface;
using Jackie.Utility.CustomExtension;
using NUnit.Framework;

#endregion

namespace Jackie.Utility.Condition.Test.WordAnalyse
{
    /// <summary> 
    /// 测试所有定义的词法分析
    /// </summary>
    [TestFixture]
    public class TestAllDefine
    {
        private IWordAnalyser wordAnalyser;

        [SetUp]
        public void SetUp()
        {
            wordAnalyser = new DefaultWordsAnalyser();
        }

        [Test]
        public void Test()
        {
            var express = @"set detail='Skomart.OrderImport.Domain.OutStoreDetail,Skomart.OrderImport.Domain';
                                     var price=110.00;
                                     var adjustPrice=10;
                                     var realPrice=price-adjustPrice;
                                     var saleNumber=1;
                                     var amount1=saleNumber*realPrice;
                                     var amount2=saleNumber*(price-adjustPrice);
                                     var realNumber=amount1/adjustPrice;
                                     var totalAmount=amount1+amount2;
                                     var bGreater1=amount1>amount2;
                                     var bGreater2=amount1>=amount2;
                                     var bLess1=amount1<amount2;
                                     var bLess2=amount1<=amount2;
                                     var bNotEqual=amount1!=amount2;
                                     var bNegation=!bNotEqual;
                                     if(bLess1==bLess2)
                                         {bLess1=!bLess2;}
                                     for(var i=0;i<100;i++)
                                         {amount1=amount1+100;}
                                     var bEqual=amount1==amount2;";
            var results = wordAnalyser.Analyse(express);

            Assert.AreEqual(143, results.Count);
            string analysedExpress = string.Empty;
            results.ForEach(item =>
                                {
                                    Console.Write("<{0}:{1}>", item.DefineType.ToString(), item.Value);
                                    analysedExpress += item.Value;
                                });
            Assert.AreEqual(analysedExpress, express.Replace(" ", "").Replace("\n", "").Replace("\r", ""));
        }

        [Test]
        public void TestNewLine()
        {
            var express = "\n";
            var regex = new Regex("^\\s$");
            Assert.AreEqual(true, regex.IsMatch(express));
        }
    }
}